/*
 * ShoppingCartGoodsHolder.java
 * business
 *
 * Created by SunDing on 2016/9/9.
 *
 * Copyright (c) 2016年 yidiandao. All rights reserved.
 */

package com.yidiandao.business.ui.widget.listview.viewholder;

import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.yidiandao.business.R;
import com.yidiandao.business.data.bean.Goods;
import com.yidiandao.business.ui.widget.listview.ViewHolder;
import com.yidiandao.business.ui.widget.view.GoodsCountMenu;
import com.yidiandao.business.utils.ImageLoader;
import com.yidiandao.business.utils.TextRenderUtils;
import com.yidiandao.business.utils.UIUtils;

/**
 * 购物车商品类型的ViewHolder
 */
public class ShoppingCartGoodsHolder extends ViewHolder {

    public RelativeLayout mRlytSelect;

    public CheckBox mCbSelect;

    public ImageView mIvGoodsImage;
    public GoodsCountMenu mGoodsCountMenu;
    private TextView mTvTitle;
    private TextView mTvPrice;

    @Override
    protected void initView(View rootView) {
        mRlytSelect = (RelativeLayout) rootView.findViewById(R.id.rlyt_select);
        mCbSelect = (CheckBox) rootView.findViewById(R.id.cb_select);
        mIvGoodsImage = (ImageView) rootView.findViewById(R.id.iv_goods_image);
        mTvTitle = (TextView) rootView.findViewById(R.id.tv_title);
        mTvPrice = (TextView) rootView.findViewById(R.id.tv_price);
        mGoodsCountMenu = (GoodsCountMenu) rootView.findViewById(R.id.goods_count_menu);
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_shopping_cart_goods;
    }

    public void refreshUI(Goods goods) {
        ImageLoader.loadImage(mContext, mIvGoodsImage, goods.getGoodsThumb());
        mTvTitle.setText(goods.getGoodsName());
        mCbSelect.setChecked(goods.isSelected());
    }

    public void setGoodsPriceAndCount(float price, int count, int stockNumber) {
        mTvPrice.setText(TextRenderUtils.getBeautyPrice(price + "", null, UIUtils.dp2px(16), UIUtils.dp2px(13)));

        // 必须先设置max
        mGoodsCountMenu.setMaxGoodsCount(stockNumber);
        mGoodsCountMenu.setGoodsCount(count);
    }

    public void refreshGoodsCountMenuMode(boolean editMode) {
        mGoodsCountMenu.setVisibility(editMode ? View.GONE : View.VISIBLE);
    }
}
